<?php
//require section
require_once dirname(__FILE__) . '/shared/config/config.php';
require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_security.php';
$title = 'Đổi Mật Khẩu';


?>

<!DOCTYPE html>
<html>
    <head>
        <?php
        require_once DOCUMENT_ROOT . DIR_INCLUDE . 'head.php';
        ?>
    </head>
    <body>
        <div class="uk-container uk-container-center uk-margin-top">
            <?php
            require_once DOCUMENT_ROOT . DIR_INCLUDE . 'menu.php';
            require_once DOCUMENT_ROOT . DIR_INCLUDE . 'slider.php';

            $email = $_SESSION['user'];
            $password_old = "";
            $password = "";
            $password_confirm = "";
            if (!empty($_POST)) {
                if (!empty($_POST['txt_password_old'])) {
                    $password_old = $_POST['txt_password_old'];
                }
                if (!empty($_POST['txt_password'])) {
                    $password = $_POST['txt_password'];
                }
                if (!empty($_POST['txt_password_confirm'])) {
                    $password_confirm = $_POST['txt_password_confirm'];
                }
                $error_show = api_security::validate_change_password($email, $password_old, $password,
                        $password_confirm);
                if (empty($error_show)) {
                    if (api_security::change_password($email, $password)) {
                        $success_info = "Đổi mật khẩu thành công.";
                    }
                }
            }
            ?>

            <!-- Changable content -->
            <section id="main-content" class="ts-body-container uk-panel uk-panel-box ts-padding-large">
                <article class="uk-article">
                    <h1 class="uk-article-title ts-color-primary">Đổi mật khẩu</h1>
                    <hr class="uk-article-divider">
                    <div>
                        <form name="form_data" id="form_data" class="uk-form" method="POST" enctype="multipart/form-data" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">

                            <!-- Hidden Value Section -->

                            <!-- End Hidden Value Section -->
                            <?php
                            if (!empty($error_show)) {?>
                            <div class="error">Lỗi: <?php echo $error_show; ?></div>
                            <?php
                            } else if (!empty($success_info)) {?>
                            <div class="success"><?php echo $success_info; ?></div>
                            <?php
                            }?>

                            <table class="ts-table">
                                <tr>
                                    <th><label for="txt_password_old">Mật Mã Cũ:<span class="ts-alert">*</span></label></th>
                                    <td><input name="txt_password_old" class="uk-form-width-large" value="" type="password" placeholder="Mật mã cũ" required></td>
                                </tr>
                                <tr>
                                    <th><label for="txt_password">Mật Mã Mới:<span class="ts-alert">*</span></label></th>
                                    <td><input name="txt_password" class="uk-form-width-large" value="" type="password" placeholder="Mật mã mới" required></td>
                                </tr>
                                <tr>
                                    <th><label for="txt_password_confirm">Xác Nhận Mật Mã Mới:<span class="ts-alert">*</span></label></th>
                                    <td><input name="txt_password_confirm" class="uk-form-width-large" value="" type="password" placeholder="Xác nhận mật mã mới" required></td>
                                </tr>
                                <tr>
                                    <th></th>
                                    <td><input type="submit" name="btn_submit" value="Đổi mật khẩu" class="uk-button uk-button-large uk-button-primary"></td>
                                </tr>
                            </table>
                        </form>
                    </div>
                </article>
            </section>
            <!-- End changable content -->

            <?php
            require_once DOCUMENT_ROOT . DIR_INCLUDE . 'footer.php';
            ?>
        </div>
    </body>
</html>